package com.aaa.vegetablemarketexpress.service.impl;

import com.aaa.vegetablemarketexpress.dao.OperateLogDao;
import com.aaa.vegetablemarketexpress.entity.OperLog;
import com.aaa.vegetablemarketexpress.service.OperateService;
import com.aaa.vegetablemarketexpress.util.CustomException;
import com.aaa.vegetablemarketexpress.util.Page;
import com.aaa.vegetablemarketexpress.util.ResultStatus;
import com.aaa.vegetablemarketexpress.vo.OperLogCountVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @FileName: OperateLogServiceImpl
 * @Description:
 * @Author: HQH
 * @CreateTime: 2025/9/17 16:04
 * @Version: 1.0.0
 */
@Service
public class OperateLogServiceImpl implements OperateService {
    @Resource
    private OperateLogDao operateLogDao;
    @Override
    public int add(OperLog operLog) {
        return operateLogDao.add(operLog);
    }

    /**
     * 分页查询
     * @param page
     * @return
     */
    @Override
    public PageInfo<OperLog> selectOperLogList(Page<OperLog> page) {
        Integer pageNo = page.getPageNo();
        Integer pageSize = page.getPageSize();
        if (pageNo == null || pageSize == null||pageNo == 0||pageSize == 0){
            throw new CustomException(ResultStatus.PARAM_ISNULL.getStatusCode(), ResultStatus.PARAM_ISNULL.getStatusMsg());
        }
        PageHelper.startPage(pageNo, pageSize);
        OperLog operLog = page.getData();
        List<OperLog> operLogList = operateLogDao.selectOperLogList(operLog);
        return new PageInfo<>(operLogList);
    }

    /**
     * 根据年月查询echats图表展示数据
     * @param yearMonth
     * @return
     */
    @Override
    public List<OperLogCountVo> queryEchartsDataByYearMonth(String yearMonth) {
        return operateLogDao.queryEchartsDataByYearMonth(yearMonth);
    }
}
